#include "test_CtcpClient2.h"

TestClient::TestClient() {
	isConnect = false;
	DebugL;
}
TestClient::~TestClient() {
	DebugL;
}


 void TestClient::onConnect(const SockException &ex){
         //连接结果事件
         isConnect = true;
         InfoL << (ex ?  ex.what() : "success");

 		{
 			string sql_ip1 = "192.168.0.91";
 			unsigned short sql_port1 = 3306;
 			// std::string db_name1 = "test_db";
 			std::string db_name1 = "svis";
 			string user1 = "root";
 			string password1 = "root";
 			string character1 = "utf8mb4";

 			bool iscon = false;
 			do
 			{
 				try
 				{
 					SqlPool::Instance().Init(sql_ip1, sql_port1, db_name1, user1, password1);
 					iscon = false;
 				}
 				catch (const std::exception& ex)
 				{
                    DebugL << "Exception sql: " << ex.what() << endl;
 					iscon = true;
 					sleep(1);
 				}
 			} while (iscon);

 			SqlPool::Instance().setSize(3 + thread::hardware_concurrency());
 		}
 }


void SqlPool_init(){
		{
			string sql_ip1 = "192.168.0.91";
			unsigned short sql_port1 = 3306;
			// std::string db_name1 = "test_db";
			std::string db_name1 = "svis";
			string user1 = "root";
			string password1 = "root";
			string character1 = "utf8mb4";

			bool iscon = false;
			do
			{
				try
				{
					SqlPool::Instance().Init(sql_ip1, sql_port1, db_name1, user1, password1);
					iscon = false;
				}
				catch (const std::exception& ex)
				{
					cout << "Exception sql: " << ex.what() << endl;
					iscon = true;
					sleep(1);
				}
			} while (iscon);

			SqlPool::Instance().setSize(3 + thread::hardware_concurrency());
		}
}

 //    void TestClient::onConnect(const SockException &ex){
 //        //连接结果事件
 //        isConnect = true;
 //        // SqlPool_init();
 //        InfoL << (ex ?  ex.what() : "success");
 //}
     void TestClient::onRecv(const Buffer::Ptr &pBuf){
         //接收数据事件
         DebugL << pBuf->data() << " from port:" << get_peer_port();
     }
     void TestClient::onFlush(){
         //发送阻塞后，缓存清空事件
         DebugL;
     }
     void TestClient::onErr(const SockException &ex){
         //断开连接事件，一般是EOF
         WarnL << ex.what();
     }
     void TestClient::onManager(){
         ////定时发送数据到服务器
         //auto buf = BufferRaw::create();
         //if(buf){
         //    buf->assign("[BufferRaw]\0");
         //    (*this) << _nTick++ << " "
         //            << 3.14 << " "
         //            << string("string") << " "
         //            <<(Buffer::Ptr &)buf;
         //}
     }